﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;

namespace DAO
{
    public class NhomThanhVienDAO
    {
        public static NhomThanhVienDTO LayNhomThanhVienTheoID(int id)
        {
            MyDataBaseDataContext myDB = new MyDataBaseDataContext();
            NHOM_THANH_VIEN temp = myDB.NHOM_THANH_VIENs.Single(c => c.ID == id);
            return new NhomThanhVienDTO(temp.ID, temp.TenNhomThanhVien);
        }

        public static bool ThemNhomThanhVien(NhomThanhVienDTO nhomthanhvienDTO)
        {
            NHOM_THANH_VIEN temp = new NHOM_THANH_VIEN();
            temp.ID = nhomthanhvienDTO.ID;
            temp.TenNhomThanhVien = nhomthanhvienDTO.TenNhomThanhVien;
            MyDataBaseDataContext myDB = new MyDataBaseDataContext();
            try
            {
                myDB.NHOM_THANH_VIENs.InsertOnSubmit(temp);
                myDB.SubmitChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public static bool XoaNhomThanhVienTheoID(int id)
        {
            MyDataBaseDataContext myDB = new MyDataBaseDataContext();
            NHOM_THANH_VIEN temp = myDB.NHOM_THANH_VIENs.Single(c => c.ID == id);
            try
            {
                myDB.NHOM_THANH_VIENs.DeleteOnSubmit(temp);
                myDB.SubmitChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
}
